#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>
    button {
        background: #758ef0;
        color: #FFF;
        border: none;
        border-radius: 15px;
    }
</style>
#end

#define content()
<div class="x-body">
    <label class="layui-form-label">专家姓名</label>
    <div class="layui-input-inline">
        <input type="text" id="name" name="name" placeholder="姓名" class="layui-input"/>
    </div>
    <div class="layui-input-inline" style="width : 80px">
        <button class="layui-btn" lay-submit="" id="search"><i class="layui-icon">&#xe615;</i>
        </button>
    </div>

    <!--隐藏id-->
    <input type="text" id="id" name="id"
           class="layui-input layui-disabled layui-hide" value="#(id)" required/>

    <div class="layui-row">
        <table id="dateTable" lay-filter="dateTable"></table>
    </div>
    <br/>
    <br/>
    <div class="layui-inline x-center">
        <button type="button" class="layui-btn" style="width: 100px;" id="submit">完成</button>
    </div>
</div>

<script type="text/html" id="barOption">
    #shiroHasPermission('/app/project/inviteReview')
    #[[
    {{#  if(!d.isInvite){ }}
    ]]#
    <a class="layui-btn layui-btn-xs" lay-event="invite">选择</a>

    #[[
    {{# } else if(d.isInvite){ }}
    ]]#
    <a class="layui-btn layui-btn-disabled layui-btn-xs" disabled="disabled">√已选择</a>
    #[[
    {{#  } }}
    ]]#
    #end
</script>

#end

#define js()
<script type="text/javascript">

    var projectID = "#(projectID)";
    var orgType = "#(orgType)";
    var num = "#(num)";
    layui.use(['table', 'layer'], function () {
        var table = layui.table, layer = layui.layer;

        // 审核通过的表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , id: 'dateTable'
            , even: true //开启隔行背景
            , size: 'sm' //小尺寸的表格
            , height: 'full-150'    //容器高度
            , contentType: 'application/json; charset=UTF-8'
            , cols: [[                  //标题栏
                {type: 'numbers', fixed: true, unresize: true}
                , {field: 'name', title: '姓名', width: 150, sort: true}
                , {field: 'sex', title: '性别', width: 100, sort: true}
                , {field: 'phone', title: '电话号码', width: 160, sort: true}
                , {field: 'address', title: '地址', width: 200, sort: true}
                , {fixed: 'right', title: '操作', align: 'center', toolbar: '#barOption'} //这里的toolbar值是模板元素的选择器
            ]]
            , url: '#(ctxPath)/app/OrgStructure/personForOrgListApi?orgType=' + orgType + "&projectID=" + projectID
            , method: 'get'
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , initSort: {
                field: 'createTime'//按照时间进行默认排序
                , type: 'desc'
            }
            , page: false
            , limits: [30, 60, 90, 150, 300]
            , limit: 30 //默认采用30
            , loading: true
            , done: function (res, curr, count) {
            }
        });

        table.on('tool(dateTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'invite') {
                $.getJSON(
                    '#(ctxPath)/app/project/chooseExpert?id=' + data.id + '&projectId=' + projectID + "&num=" + num,
                    function (res) {
                        if (res.status) {
                            table.reload('dateTable', {
                                url: '#(ctxPath)/app/OrgStructure/personForOrgListApi?orgType=' + orgType + "&projectID=" + projectID
                            });
                        } else {
                            layer.msg("选择人数已达上限，选择已完成！");
                            return false;
                        }
                    });
            }
        });

        $('#search').click(function () {
            table.reload('dateTable', {
                url: '#(ctxPath)/app/expert_group/tableData?name=' + $('#name').val()
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        $('#submit').click(function () {
            pop_close();
        });

    });

</script>
#end